﻿#include "ObjectPropertyEditEntry.h"
#include <QPointer>
#include "StringEditEntry.h"
#include "ObjectPropertyEditEntryFactory.h"

REGISTER_PROPERTY_EDIT_ENTRY(Object)

struct ObjectPropertyEditEntry::ObjectEditorEntryPrivate {
    QPointer<QObject> object;
    QPointer<StringEditEntry> entryObjectName;
};

ObjectPropertyEditEntry::ObjectPropertyEditEntry(QWidget *parent) : PropertyEditEntry{parent} {
    p.reset(new ObjectEditorEntryPrivate);
    setTitle(tr("QObject"));
}

ObjectPropertyEditEntry::ObjectPropertyEditEntry(void *object, QWidget *parent) {
    p.reset(new ObjectEditorEntryPrivate);
    PropertyEditEntry(object, parent);
    setTitle(tr("QObject"));
    setObject(object);
}

void ObjectPropertyEditEntry::setObject(void *object) {
    p->object = static_cast<QObject*>(object);
    p->entryObjectName = new StringEditEntry;
    p->entryObjectName->setTitle(tr("Object name"));
    appendChildEntry(p->entryObjectName);
    Tick();
}

void ObjectPropertyEditEntry::Tick() {
    if(!p->object) {
        return ;
    }

    p->entryObjectName->setValue(p->object->objectName());
}
